import Vue from 'vue'
import Router from 'vue-router'
import Login from "@/pages/login";
import Nav from "@/pages/nav";

Vue.use(Router)

const routes = [
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
  {
    path: "/",
    name: "Nav",
    component: Nav,
    children: [
      {
        path: "",
        redirect: "home",
      },
      {
        path: "home",
        name: "Home",
        component: () => import("@/pages/home"),
      },
      {
        path: "search",
        name: "Search",
        component: () => import("@/pages/search"),
      },
      {
        path: 'search/:id',
        name: 'SearchDetail',
        props: true,
        component: () => import('@/pages/search-detail'),
      },
      {
        path: "wiki",
        name: "Wiki",
        component: () => import("@/pages/wiki"),
      },
      {
        path: "houses",
        name: "Houses",
        component: () => import("@/pages/houses"),
      },
      {
        path: "help",
        name: "Help",
        component: () => import("@/pages/help"),
      },
    ]
  },

  {
    path: '/404',
    component: () => import("@/pages/errors/404"),
    hidden: true
  },

  { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes,
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router;
